package com.example.myapplication.activity.advanced_activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;

import com.example.myapplication.R;

public class ShareWriteActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sharewrite_activitity);
        SharedPreferences sharedPreferences = getSharedPreferences("data", MODE_PRIVATE);
        // 写入数据
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("name", "张三");
        editor.putInt("age", 18);
        editor.putBoolean("married", false);
        editor.apply();
        // 读取数据
        String name = sharedPreferences.getString("name", "");
        int age = sharedPreferences.getInt("age", 0);
        boolean married = sharedPreferences.getBoolean("married", false);
        System.out.println("name:" + name + " age:" + age + " married:" + married);
    }
}